package com.goodving.guli.view;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by john on 2015/11/23.
 */
public final class BitmapDescriptor implements Parcelable, Cloneable {
    public static final BitmapDescriptorCreator CREATOR;
    int f13017a;
    int f13018b;
    Bitmap f13019c;

    static {
        CREATOR = new BitmapDescriptorCreator();
    }

    BitmapDescriptor(Bitmap bitmap) {
        this.f13017a = 0;
        this.f13018b = 0;
        if (bitmap != null) {
            this.f13017a = bitmap.getWidth();
            this.f13018b = bitmap.getHeight();
//            this.f13019c = m18160a(bitmap, C2279u.m18063a(this.f13017a), C2279u.m18063a(this.f13018b));
            bitmap.recycle();
        }
    }

    private BitmapDescriptor(Bitmap bitmap, int i, int i2) {
        this.f13017a = 0;
        this.f13018b = 0;
        this.f13017a = i;
        this.f13018b = i2;
        this.f13019c = bitmap;
    }

    private Bitmap m18160a(Bitmap bitmap, int i, int i2) {
        Bitmap createBitmap = Bitmap.createBitmap(i, i2, bitmap.hasAlpha() ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(createBitmap);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        canvas.drawBitmap(bitmap, 0.0f, 0.0f, paint);
        return createBitmap;
    }

    public BitmapDescriptor clone() {
        try {
            return new BitmapDescriptor(Bitmap.createBitmap(this.f13019c), this.f13017a, this.f13018b);
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public int describeContents() {
        return 0;
    }

    public boolean equals(Object obj) {
        boolean z = false;
        if (this.f13019c == null || this.f13019c.isRecycled() || obj == null) {
            return z;
        }
        if (this == obj) {
            return true;
        }
        if (getClass() != obj.getClass()) {
            return z;
        }
        BitmapDescriptor bitmapDescriptor = (BitmapDescriptor) obj;
        if (bitmapDescriptor.f13019c == null || bitmapDescriptor.f13019c.isRecycled() || this.f13017a != bitmapDescriptor.getWidth() || this.f13018b != bitmapDescriptor.getHeight()) {
            return z;
        }
        try {
            return this.f13019c.sameAs(bitmapDescriptor.f13019c);
        } catch (Throwable th) {
            return z;
        }
    }

    public Bitmap getBitmap() {
        return this.f13019c;
    }

    public int getHeight() {
        return this.f13018b;
    }

    public int getWidth() {
        return this.f13017a;
    }

    public void recycle() {
        if (this.f13019c != null && !this.f13019c.isRecycled()) {
            this.f13019c.recycle();
            this.f13019c = null;
        }
    }

    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeParcelable(this.f13019c, i);
        parcel.writeInt(this.f13017a);
        parcel.writeInt(this.f13018b);
    }
}

